(function() {
	'use strict';

	var vm = this;
	var url = 'ws://test:123456@192.168.1.100:8100/';//服务器地址、用户名密码

	activate();
	function activate() {
		gatewayStatus();
		function gatewayStatus() {
			var topic = 'gateway/' + eui + '/stats';//监听主题
			Sockets(topic, function (d) {
				congsole.log(d);//监听结果
			});
		}
		function Sockets(topic, callback) {
			angularLoad.loadScript("./mqtt.min.js").then(() => {
				var client = mqtt.connect(url);
				// 订阅主题
				client.on('connect', function () {
					client.subscribe(topic);
				})
				client.on('message', function (topic, message) {
					callback(JSON.parse(message.toString()));
				});
			}).catch(err => {
				console.log("load mqtt error:", err);
			})
		}
	}
})();
